package com.gcd.alienandwheel.actor;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;

/**
 *
 * @author Rezan Achmad
 */
public class MyButton extends Button {

    public MyButton(String name) {
        super(name);
    }

    public MyButton(String name, Texture texture) {
        super(name, texture);
    }

    public MyButton(String name, TextureRegion textureRegion) {
        super(name, textureRegion);
    }

    public MyButton(String name, TextureRegion unpressedRegion, TextureRegion pressedRegion) {
        super(name, unpressedRegion, pressedRegion);
    }

    @Override
    protected boolean touchUp(float x, float y, int pointer) {
        if (!pressed) {
            return false;
        }

        boolean isHit = x > 0 && y > 0 && x < width && y < height;
        if (!isHit) {
            return false;
        }

        parent.focus(null);
        pressed = false;
        if (clickListener != null) {
            clickListener.clicked(this);
        }
        return true;
    }
}
